#include "Exception.hpp"

namespace sl
{
	namespace tmp
	{
		ExceptionT::ExceptionT(sl::ErrorCode code, const std::string& filename, const long linenumber) : myMessage(""), myErrorCode(code), myFilename(filename), myLinenumber(linenumber)
		{
			::sl::LogManager->Get("error")->Write(sl::LogType::None, what());
		}

		ExceptionT::ExceptionT(const std::string& text, sl::ErrorCode code, const std::string& filename, const long linenumber) : myMessage(text), myErrorCode(code), myFilename(filename), myLinenumber(linenumber)
		{
			::sl::LogManager->Get("error")->Write(sl::LogType::None, what());
		}

		std::string ExceptionT::GetMessage()
		{
			return myMessage;
		}

		sl::ErrorCode ExceptionT::GetErrorCode()
		{
			return myErrorCode;
		}

		std::string ExceptionT::GetFilename()
		{
			return myFilename;
		}

		long ExceptionT::GetLinenumber()
		{
			return myLinenumber;
		}

		std::string ExceptionT::what()
		{
			std::stringstream ss;
			ss << "Error " << myErrorCode << " (" << ErrorCodeToString(myErrorCode) << "): " << ((myMessage != "") ? myMessage + ", " : "") << "file: \"" << myFilename << "\" in line: " << myLinenumber << "\n";
			return ss.str();
		}
	}
}